home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource4 / 253_01 / anyfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  640 b   |  30 lines

  1.                                          /* Chapter 10 - Program 7 */
  2. #include "stdio.h"
  3.  
  4. void main()
  5. {
  6. FILE *fp1;
  7. char oneword[100],filename[25];
  8. char *c;
  9.  
  10.    printf("Enter filename -> ");
  11.    scanf("%s",filename);         /* read the desired filename */
  12.    fp1 = fopen(filename,"r");
  13.  
  14.    do {
  15.       c = fgets(oneword,100,fp1); /* get one line from the file */
  16.       if (c != NULL)
  17.          printf("%s",oneword);    /* display it on the monitor  */
  18.    } while (c != NULL);          /* repeat until NULL          */
  19.  
  20.    fclose(fp1);
  21. }
  22.  
  23.  
  24.  
  25. /* Result of execution
  26.  
  27. (The file selected is listed on the monitor)
  28.  
  29. */
  30.